/**
 * 统一JSON返回封装类
 */
export class JsonResp {
  code: number;
  data?: any;

  constructor(data?: any, code = 0) {
    this.data = data;
    this.code = code;
  }
}

/**
 * 错误状态
 */
export class ErrorStat extends JsonResp {
  message: string;
  status: number;

  constructor(code: number, message: string, status = 200) {
    super(undefined, code);
    this.message = message;
    this.status = status;
  }

  toJSON() {
    return {
      code: this.code,
      message: this.message,
    };
  }
}

/**
 * 业务状态错误码
 */
export const stats = {
  ErrDataBaseError: new ErrorStat(10001, '数据库操作失败', 500), 
  ErrUserNotFound: new ErrorStat(30001, "用户不存在", 404),
  ErrTaskNotFound: new ErrorStat(30002, "任务不存在", 404),
  ErrUserAccountExist: new ErrorStat(30003, "已存在使用该账号的用户"),
  ErrUserAccountDisable: new ErrorStat(30003, "该账号的用户已经被禁用"),
  ErrUserNicknameExist: new ErrorStat(30004, "已存在使用该昵称的用户"),
  ErrPasswordIncorrect: new ErrorStat(30005, "密码错误"),
  ErrOldPasswordIncorrect: new ErrorStat(30006, "旧密码输入错误"),
  ErrPasswordNotUniform: new ErrorStat(30007, "两次输入的密码不一致"),
  ErrUserIdNotUniform: new ErrorStat(30008, "当前用户id与数据表内id不一致"),
  ErrSessionNotFound: new ErrorStat(40001, "会话不存在"),
  ErrSessionIsImpty: new ErrorStat(40002, "会话不能为空"),

};
